import Vue from "vue";
import VueRouter from "vue-router";

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch((err) => err);
};

const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace (location) {
  return originalReplace.call(this, location).catch((err) => err);
};

Vue.use(VueRouter);

/**
 * path 跳转路径
 * name 页面名称
 * component 页面路径
 * meta 定义配置信息 role：角色
 * keepAlive: true 将会缓存本页面 false | undefined 不会缓存页面
 * isJump: <Boolean> 页面跳转权限设置 true 不需要权限就可跳转 false 需要权限跳转的页面
 */
const routes = [
  {
    path: "/",
    redirect: "/factoryDrawing",
  },
  {
    path: "/",
    name: "",
    // 首页
    component: () => import(/* webpackChunkName: "LogIn" */ "@v/layout/index.vue"),
    children: [
      {
        path: "/qualityManagement",
        name: "QualityManagement",
        component: () => import(/* webpackChunkName: "FullConnectivity" */ "@v/qualityManagement/index.vue"),
      },
      {
        path: "/serviceManagement",
        name: "ServiceManagement",
        component: () => import(/* webpackChunkName: "FullConnectivity" */ "@v/serviceManagement/index.vue"),
      },
      {
        path: "/operationPerformance",
        name: "OperationPerformance",
        component: () => import(/* webpackChunkName: "FullConnectivity" */ "@v/operationPerformance/index.vue"),
      },
      {
        path: "/factoryDrawing",
        name: "FactoryDrawing",
        component: () => import(/* webpackChunkName: "FullConnectivity" */ "@v/factoryDrawing/index.vue"),
      },
      {
        path: "/safetyEnvironmentalProtection",
        name: "SafetyEnvironmentalProtection",
        component: () =>
          import(/* webpackChunkName: "FullConnectivity" */ "@v/safetyEnvironmentalProtection/index.vue"),
      },
      {
        path: "/productionManagement",
        name: "ProductionManagement",
        component: () => import(/* webpackChunkName: "FullConnectivity" */ "@v/productionManagement/index.vue"),
      },
      {
        path: "/workshopManagement",
        name: "WorkshopManagement",
        component: () => import(/* webpackChunkName: "FullConnectivity" */ "@v/workshopManagement/index.vue"),
      },
    ],
  },
];

const router = new VueRouter({
  // mode: "history",
  base: process.env.BASE_URL,
  routes,
});

// 通过筛选拿到数据

export default router;
